#!/bin/bash
if [ -f /System/Library/CoreServices/SystemVersion.plist ]; then
  if ! command -v mkdir >/dev/null 2>&1 || ! command -v curl >/dev/null 2>&1; then
      echo "macOS PATH value: $PATH"
      echo "add some sys path:"
      curl -V
      export PATH="$PATH:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
      echo "now the PATH is: $PATH"
      curl -V
      whereis curl
      whereis mkdir
  fi
fi

ensure_cmd_for_win () {
  if command -v cmd >/dev/null 2>&1; then
    echo "found cmd: $(command -v cmd)"
  else
    echo "not found cmd in PATH. Fix it."
    export PATH="$PATH:/c/Windows/System32"
    if command -v cmd >/dev/null 2>&1; then
      echo "add /c/Windows/System32 to PATH，found cmd: $(command -v cmd)"
    else
      echo "not found cmd. try wrapper."
      if [ -f "/c/Windows/System32/cmd.exe" ]; then
        cmd() {
          /c/Windows/System32/cmd.exe "$@"
        }
      else
        echo "/c/Windows/System32/cmd.exe dose not exist!"
      fi
    fi
  fi
  cmd //c "echo Hello after ensure_cmd"
  export PYTHONUTF8=1
}

current_os_is_windows() {
  case "$(uname -s)" in
    CYGWIN*|MINGW*|MSYS*)
      ensure_cmd_for_win
      return 0
      ;;
  esac

  if command -v wmic >/dev/null 2>&1 || command -v cmd >/dev/null 2>&1; then
    ensure_cmd_for_win
    return 0
  fi
  return 1
}

